home *** CD-ROM | disk | FTP | other *** search
- /*
- "mic_memory.cpp"
-
- This file contains Mic-1 objects which exist solely as memory, be it registers
- or massive control store arrays.
- */
-
- #include <iostream.h>
- #include <fstream.h>
- #include <iomanip.h>
-
- #include "mic_main.h"
- #include "mic_memory.h"
- #include "mic_global_functions.h"
-
- short InitMicMemory (Mic_1_Class& Mic)
- {
- Str32 fileNameStr;
- char *fileNameP;
- GetIndString(fileNameStr, 129, 1);
- fileNameP = P2CStr(fileNameStr);
- ifstream MemInitFile(fileNameP);
-
- for (int n=0; n<kMaxRAM; n++)
- Mic.Memory.putNthWord (n,0);
-
- if (MemInitFile.is_open())
- {
- MemInitFile >> Mic.Memory;
- }
- else
- {
- ofstream newMemFile(fileNameP);
- if (newMemFile.is_open())
- {
- newMemFile << Mic.Memory;
- return 130;
- }
- else
- return 131;
- }
- return 0;
- }
-
- Boolean MemoryClass::putNthWord (short n, unsigned short newWord)
- {
- if ((n>=0) && (n<kMaxRAM))
- {
- mem[n] = newWord;
- return true;
- }
- else
- return false;
- }
-
- void MemoryClass::output (Mic_1_Class& Mic)
- {
- Mic.MBR.input_Memory(getNthWord(addr));
- }
-
- ostream& operator << (ostream& s, MemoryClass& m)
- {
- int extra = (kMaxRAM%10>0) ? 1:0;
- int numRows = 10;
- int numColumns;
-
- s << "MEMORY: " << endl;
- for (int i=0; i<numRows; i++)
- {
- s << setw(4) << setfill(' ') << right << i*10 << ": ";
- numColumns = (kMaxRAM - i*10 >= 10) ? 10:kMaxRAM - i*10;
- s << hex << uppercase;
- for (int j=0; j < numColumns; j++)
- {
- s << setw(4) << setfill('0') << right << m.getNthWord(i*10 + j);
- if (j < 10 - 1)
- s << " ";
- }
- s << resetiosflags(ios::hex | ios::uppercase);
- if (i < numRows - 1)
- s << endl;
- }
- if (numRows < kMaxRAM/10 + extra)
- s << endl << "<abbreviated>" << endl;
- return s;
- }
-
- istream& operator >> (istream& s, MemoryClass& m)
- {
- unsigned short numwords, memword;
- short counter = 0;
-
- s >> numwords;
- while (counter < numwords)
- {
- s >> memword;
- s >> hex >> uppercase >> memword;
- s >> resetiosflags(ios::hex | ios::uppercase);
- m.putNthWord(counter++, memword);
- }
- for (int i=counter; i<kMaxRAM; i++)
- m.putNthWord(i, 0);
- return s;
- }